package org.sgroup.imenu.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class LoadBitmap {
	public static Bitmap GetBitmap(Context _ctx, String _path) {
		Bitmap thumbnail = null;
		File filePath = null;
		FileInputStream fi = null;
		try {
			filePath = new File(_ctx.getFilesDir().getAbsolutePath() + "/"
					+ _path);
			fi = new FileInputStream(filePath);
			thumbnail = BitmapFactory.decodeStream(fi);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			Log.e("getThumbnail() on internal storage", e.getMessage());
		}
		if (thumbnail == null) {
			InputStream path;
			try {
				path = _ctx.getAssets().open("img/"+_path);
				thumbnail = BitmapFactory.decodeStream(path);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.e("getThumbnail() on asset", e.getMessage());
			}
			if (thumbnail == null) {
				InputStream path1;
				try {
					path1 = _ctx.getAssets().open("img/burger-icon.png");
					thumbnail = BitmapFactory.decodeStream(path1);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					Log.e("getThumbnail() on asset", e.getMessage());
				}
			}
		}

		return thumbnail;
	}

	public static String getDataDir(Context context) throws Exception {
		return context.getPackageManager().getPackageInfo(
				context.getPackageName(), 0).applicationInfo.dataDir;
	}
}
